package com.lovo.controller;

import com.lovo.model.DTO.CourseDTO;
import com.lovo.result.ResponseResult;
import com.lovo.service.CourseService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@ResponseResult
@RequestMapping("/courses")
public class CourseController {
    @Resource
    private CourseService courseService;

    @GetMapping()
    public Object findAll(Integer page, Integer size) {
        if (page == null) {
            page = 1;
        }
        if (size == null) {
            size = 5;
        }
        return courseService.findAll(page, size);
    }

    ;

    @GetMapping("/{id}")
    public Object findById(@PathVariable("id") Integer id) {
        return courseService.findById(id);
    }

    @PutMapping("/{id}")
    public Object update(@PathVariable("id") Integer id, @RequestBody CourseDTO courseDTO) {
        courseService.update(id, courseDTO);
        return null;
    }

    ;

    @PostMapping("/addcourse")
    public Object save(@RequestBody CourseDTO courseDTO) {
        courseService.add(courseDTO);
        return null;
    }

    @DeleteMapping("/{id}")
    public Object del(Integer id) {
        courseService.del(id);
        return null;
    }

}
